from concurrent import futures
import logging

import grpc
import test_pb2
import test_pb2_grpc

class UserInfo(test_pb2_grpc.UserInfoServicer):
    def Info(self, request, context):
        print(request)

        print(request.age)
        print(request.name)
        print(request.hobby)
        print(request.info)
        print(request.height_weight)
        print(request.opening)

        return test_pb2.response(message="大家好，我是{}, 喜欢{}".format(request.name, request.opening.words))


def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))  # 多线程
    test_pb2_grpc.add_UserInfoServicer_to_server(UserInfo(), server)
    server.add_insecure_port('[::]:10086')
    server.start()
    server.wait_for_termination()


if __name__ == '__main__':
    logging.basicConfig()
    serve()

